//
//  ViewController.m
//  DEMO2
//
//  Created by J on 16/3/24.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //实现就是 pan手势 + 修改bounds实现
//    UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
//    [self.view addSubview:scrollView];
//    
//    UISwitch* swit = [UISwitch new];
//    [scrollView addSubview:swit];
//    
//    scrollView.contentSize = CGSizeMake(0 , 1000);
//    scrollView.delegate = self;
    
    
    //自己实现
    UIView *scrollView = [[UIView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:scrollView];
    UISwitch* swit = [UISwitch new];
    [scrollView addSubview:swit];

    
    //创建pan手势
    UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
    [scrollView addGestureRecognizer:pan];
    
    
    
}

//手指拖动调用
- (void)pan:(UIPanGestureRecognizer*)pan{
    
    //获取手指偏移量
   CGFloat transY =  [pan translationInView:pan.view].y;
    
    CGRect bounds = pan.view.bounds;
    bounds.origin.y -= transY;   //向上滑 bounds.y增加偏移量的y是－的所以取反
    pan.view.bounds = bounds;
    
    
    //复位
    [pan setTranslation:CGPointZero inView:pan.view];
    
    
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
//    不断改变scrollView的bounds 来改变内部的子视图的位置  bounds x,y 正书 子视图向上跑  -负数 向下跑
    NSLog(@"%@  %@",NSStringFromCGRect(scrollView.bounds),NSStringFromCGPoint(scrollView.contentOffset));
}

@end
